<?php 
    // 验证用户是否登录
    session_start();
    $user=isset($_SESSION['user'])?$_SESSION['user']:false;
    if(!$user){
        exit('您还未登录，请登录后再发表博客');
    }
    // 连接数据库
    require_once $_SERVER['DOCUMENT_ROOT'].'/blog/lib/Db.php'; //绝对地址
    $db=new Db();
    // 读取博客分类
    $cates=$db->table('cates')->lists();
    include_once './template/header.php';
?>

    <style>
        .form .input-group{
            margin:20px 0;
        }
    </style>
    <div class="form">
        <div class="input-group input-group-sm">
            <span class="input-group-addon">标 &nbsp; 题</span>
            <input type="text" class="form-control" name="title" placeholder="请输入博客标题">
        </div>
        <div class="input-group input-group-sm">
            <span class="input-group-addon">分 &nbsp; 类</span>
            <select class="form-control" name="cid">
                <?php foreach($cates as $cate){?>
                <option value="<?php echo $cate['id']?>"><?php echo $cate['title']?></option>
                <?php }?>
            </select>
        </div>
        <div class="input-group input-group-sm">
            <span class="input-group-addon">关键字</span>
            <input type="text" class="form-control" name="keywords" placeholder="请输入博客关键字">
        </div>
        <div class="input-group input-group-sm">
            <span class="input-group-addon">描 &nbsp; 述</span>
            <input type="text" class="form-control" name="desc" placeholder="请输入博客描述">
        </div>
        <div class="input-group input-group-sm">
            <span class="input-group-addon">内 &nbsp; 容</span>
            <div id="editor"></div>
        </div>
        <button class="btn btn-primary pull-right" onclick="save()">保存</button>
    </div>
    <?php include_once './template/footer.php'?>
    <script type="text/javascript" src="static/plugins/wangEditor/wangEditor.min.js"></script>    
    <script>
        $(function(){
            initEditor(); //富文本编辑器
        })
    </script>